package com.wms.controller;

import com.wms.entity.WUser;
import com.wms.mytool.Result;
import com.wms.service.WUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户基本信息表(WUser)表控制层
 *
 * @author Li Xiaoyu
 * @since 2023-10-09 12:19:12
 */
@RestController
@RequestMapping("/user")
public class WUserController {
    /**
     * 服务对象
     */
    @Resource
    private WUserService wUserService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Integer id) {
        return new Result(200,this.wUserService.queryById(id),"success");
    }

    /**
     * 登录接口
     *
     * @return 实例对象
     */
    @GetMapping("/login/{username}/{password}")
    public Result login(@PathVariable("username") String username,@PathVariable("password") String password) {
        return this.wUserService.loginCheck(username,password);
    }

    /**
     * 注册接口
     * @param wUser 用户信息
     * @return 实例对象
     */
    @PostMapping("/register")
    public Result register(@RequestBody WUser wUser){
        return this.wUserService.userRegister(wUser);
    }

    /**
     * 查询所有用户接口
     * @return 实例对象
     */
    @GetMapping("/selectAll")
    public Result selectAll(){
        return this.wUserService.selectAllUser();
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody WUser wUser){
        return this.wUserService.updateUser(wUser);
    }

    @DeleteMapping("/deleteUser/{userid}")
    public Result deleteUserById(@PathVariable("userid") Integer userid){
        return this.wUserService.deleteUserById(userid);
    }

}

